package com.pmsystem.controller;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.pmsystem.pojo.Accident;
import com.pmsystem.pojo.CleanArea;
import com.pmsystem.pojo.CleanMan;
import com.pmsystem.pojo.CleanMis;
import com.pmsystem.service.CleanService;



@Controller
@RequestMapping("clean")
public class CleanController {

	@Autowired
	CleanService cleanService;
	
	/**
	 * <p>Title: index</p >  
	 * <p>Description: 主页路径</p >  
	 * @author 魏家洛
	 * @param mv
	 * @return
	 */
	@RequestMapping("index")
	public String index(ModelAndView mv) {
		return "clean/clean_index";
	}
	
	
	//保洁区域操作
	/**
	 * <p>Title: findAreaPage</p >  
	 * <p>Description:传入页码和页大小获取页码对应保洁区域信息</p >  
	 * @author 魏家洛
	 * @param pageNo
	 * @param pageSize
	 * @return
	 */
	@RequestMapping("findareapage")
	@ResponseBody
	public Map findAreaPage(Integer pageNo,Integer pageSize,String condition){
		return cleanService.findAreaPage(pageNo,pageSize,condition);
	}
	/**
	 * <p>Title: deleteclean</p >  d
	 * <p>Description:删除保洁区域信息</p >  
	 * @author 魏家洛
	 * @param id
	 * @return
	 */
	@RequestMapping("deletearea")
	@ResponseBody
	public boolean deleteArea(Integer id){
		return cleanService.deleteArea(id);
	}
	/**
	 * <p>Title: updateArea</p >  
	 * <p>Description: 更新保洁区域信息</p >  
	 * @author 魏家洛
	 * @param id
	 * @param mv
	 * @return
	 */
	@RequestMapping("updatearea")
	public ModelAndView updateArea(Integer id,ModelAndView mv){
		mv.addObject("cleanArea",cleanService.selectArea(id));
		mv.setViewName("clean/update_area");
		return mv;
	}
	@RequestMapping("updatearea1")
	public String updateArea1(CleanArea cleanArea){
		cleanService.updateArea(cleanArea);
		return "redirect:index#area";
	}
	/**
	 * <p>Title: addArea</p >  
	 * <p>Description: 添加保洁区域信息</p >  
	 * @author 魏家洛
	 * @param cleanAreaName
	 * @return
	 */
	@RequestMapping("addarea")
	public String addArea(String cleanAreaName){
		cleanService.addArea(cleanAreaName);
		return "redirect:index#area";
	}
	
	
	
	//保洁人员操作
	/**
	 * <p>Title: findManPage</p >  
	 * <p>Description:传入页码和页大小获取页码对应保洁人员信息</p >  
	 * @author 魏家洛
	 * @param pageNo
	 * @param pageSize
	 * @return
	 */
	@RequestMapping("findmanpage")
	@ResponseBody
	public Map findManPage(Integer pageNo,Integer pageSize,String condition){
		return cleanService.findManPage(pageNo,pageSize,condition);
	}
	/**
	 * <p>Title: deleteMan</p >  
	 * <p>Description:删除保洁人员信息</p >  
	 * @author 魏家洛
	 * @param id
	 * @return
	 */
	@RequestMapping("deleteman")
	@ResponseBody
	public boolean deleteMan(Integer id){
		return cleanService.deleteMan(id);
	}
	/**
	 * <p>Title: updateMan</p >  
	 * <p>Description: 更新保洁人员信息</p >  
	 * @author 魏家洛
	 * @param id
	 * @param mv
	 * @return
	 */
	@RequestMapping("updateman")
	public ModelAndView updateMan(Integer id,ModelAndView mv){
		mv.addObject("cleanMan",cleanService.selectMan(id));
		mv.setViewName("clean/update_man");
		return mv;
	}
	@RequestMapping("updateman1")
	public String updateMan1(CleanMan cleanMan){
		cleanService.updateMan(cleanMan);
		return "redirect:index#man";
	}
	/**
	 * <p>Title: addMan</p >  
	 * <p>Description: 添加保洁人员信息</p >  
	 * @author 魏家洛
	 * @param cleanMan
	 * @return
	 */
	@RequestMapping("addman")
	public String addMan(CleanMan cleanMan){
		cleanService.addMan(cleanMan);
		return "redirect:index#man";
	}
		
		
		
	//保洁任务操作
	/**
	 * <p>Title: findMisPage</p >  
	 * <p>Description:传入页码和页大小获取页码对应保洁任务信息</p >  
	 * @author 魏家洛
	 * @param pageNo
	 * @param pageSize
	 * @return
	 */
	@RequestMapping("findmispage")
	@ResponseBody
	public Map findMisPage(Integer pageNo,Integer pageSize,String condition,String startTime,String endTime){
		System.out.println(startTime+"..."+endTime);
		return cleanService.findMisPage(pageNo,pageSize,condition,startTime,endTime);
	}
	/**
	 * <p>Title: deleteMis</p >  
	 * <p>Description:删除保洁任务信息</p >  
	 * @author 魏家洛
	 * @param id
	 * @return
	 */
	@RequestMapping("deletemis")
	@ResponseBody
	public boolean deleteMis(Integer id){
		return cleanService.deleteMis(id);
	}
	/**
	 * <p>Title: updateMis</p >  
	 * <p>Description: 更新保洁任务信息</p >  
	 * @author 魏家洛
	 * @param id
	 * @param mv
	 * @return
	 */
	@RequestMapping("updatemis")
	public ModelAndView updateMis(Integer id,ModelAndView mv){
		mv.addObject("cleanMis",cleanService.selectMis(id));
		mv.setViewName("clean/update_mis");
		return mv;
	}
	@RequestMapping("updatemis1")
	public String updateMis1(CleanMis cleanMis){
		cleanService.updateMis(cleanMis);
		return "redirect:index#mis";
	}
	/**
	 * <p>Title: addMis</p >  
	 * <p>Description: 添加保洁任务信息</p >  
	 * @author 魏家洛
	 * @param cleanMis
	 * @return
	 */
	@RequestMapping("addmis")
	public String addMis(CleanMis cleanMis){
		cleanService.addMis(cleanMis);
		return "redirect:index#mis";
	}
	/**
	 * <p>Title: getProgress</p >  
	 * <p>Description:获取当天任务进度</p >  
	 * @author 魏家洛
	 * @return
	 */
	@RequestMapping("getprogress")
	@ResponseBody
	public int getProgress(String currentDate) {
		System.out.println(currentDate);
		return cleanService.getProgress(currentDate);
	}
}
